package com.lzx.article.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;

/**
 * @author 程序员星星
 * @date 2023/1/12
 * @Description
 */
@Getter
@AllArgsConstructor
public enum ArticleType {
    ALL(1, "全部可见"),
    PRIVATE(2, "仅我可见"),
    FANS(3, "粉丝可见");
    @EnumValue
    private final Integer type;
    @JsonValue
    private final String desc;

    public static ArticleType find(Integer type) {
        Optional<ArticleType> optional = Arrays.stream(ArticleType.values())
                .filter(articleType -> Objects.equals(articleType.getType(), type)).findAny();
        if (optional.isPresent()) {
            return optional.get();
        }
        throw new RuntimeException("type not exists");
    }
}
